(define (analyze classdef)
  (define (prewalk proc)
    (define (walk-recur exp)
      (proc exp)
      (for-each walk-recur (subexpressions exp)))
    (walk-recur classdef))
  (define (postwalk proc)
    (define (walk-recur exp)
      (for-each walk-recur (subexpressions exp))
      (now-compiling exp
		     (lambda ()
		       (proc exp))))
    (walk-recur classdef))

  (unless (is? classdef class-definition)
    (error "Top level form should be a class definition"
	   (unparse classdef)))
  (now-compiling-class classdef
		       (lambda ()
			 (analyze-structure classdef)
			 (prewire-types classdef)
			 (postwalk propagate-types))))

(define (analyze-structure exp)
  (define subs (find-subexpressions exp))
  (define (walk sub)
    (set (uses sub)
	 (cons exp
	       (uses sub)))
    (analyze-structure sub))

  (set (subexpressions exp) subs)
  (set (contains-statements? exp)
       (or (statement? exp)
	   (any contains-statements? subs)))
  (for-each walk subs))

